package handler

import (
	"iptv_server/v3/v2_src/handler/middleware"
	"iptv_server/v3/v2_src/utils/cache"
	"net/http"
	"time"
)

var (
	// fallbackAddr     string
	// 19999
	fallbackPort int
	// /files/v3/fallback"
	fallbackBasePath string

	proxyStringCache *cache.Cache[string]

	IP_STORE *recorder
)

func InitServer(mux *http.ServeMux, port int, path string) {

	fallbackPort = port

	fallbackBasePath = path

	proxyStringCache = cache.NewCache[string]("proxy String Cache", time.Minute*time.Duration(60)) // 30 min
	// stringCache = cache.NewCache[string]("string cache", time.Second*time.Duration(20)) // debug = 10 sec

	if mux == nil {
		panic("http.ServeMux is nil")
		// mux = http.DefaultServeMux
	}

	initLive(mux, middleware.WithLog)

	// initFileServer(middleware.WithLog)

	initProxy(mux, middleware.WithLog)
	initOnlineVod(mux, middleware.WithLog)

	initPlaying(mux, middleware.WithLog)

	InitPushCenter(mux, middleware.WithLog)

	initStatusCode(mux, middleware.WithLog)
	InitRecorder(mux, middleware.WithLog)

	initOthers(mux, middleware.WithLog)
	initDebug(mux, middleware.WithLog)

}

func Stop() {
	proxyStringCache.Destroy()
}
